
package ploy.lang;

import java.util.*;

/**
 * Globals is the class containing the dynamic map from symbols representing
 * global variables to their values.
 */
public class Globals {

    public static Map<Symbol,DynamicObject> globals =
	new Hashtable<Symbol,DynamicObject>();

    public static DynamicObject lookupGlobal( Symbol s )
	throws RuntimeError
    {
	DynamicObject x = globals.get( s );
	if (x != null) return x;
	else throw new RuntimeError( "Undefined variable " + s.toString() );
    }

    public static void addGlobal( Symbol s, DynamicObject d )
	throws RuntimeError
    {
	if (globals.containsKey(s)) {
	    throw new RuntimeError( "Redefinition of variable " + 
				    s.toString() );
	} else {
	    globals.put( s, d );
	}
    }
}